package com.pdsu.graduation_design.views;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.pdsu.graduation_design.MainActivity;
import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.domain.Agriculture;
import com.pdsu.graduation_design.utils.JsonUtil;
import com.pdsu.graduation_design.utils.Result;
import com.squareup.picasso.Picasso;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class AgricultureMessageDetailsActivity extends AppCompatActivity {


    private TextView title,message,username,data;
    private ImageView image;

    private Agriculture agriculture_temp;
    private String user_name_str;
    @Override
    protected void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agriculture_message_details);
        init();
        try {
            bind();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }

    void init(){
        title=findViewById(R.id.ac_agriculture_message_title);
        message=findViewById(R.id.ac_agriculture_message_message);
        username=findViewById(R.id.ac_agriculture_message_user);
        data=findViewById(R.id.ac_agriculture_message_time);
        image=findViewById(R.id.ac_agriculture_message_image);
        user_name_str=getIntent().getStringExtra("username");
    }
    void bind() throws JsonProcessingException {
        agriculture_temp =getData();
        System.out.println(agriculture_temp.toString());
        System.out.println(agriculture_temp);
        title.setText(agriculture_temp.getTitle());
        username.setText(user_name_str);
        Picasso.with(getApplicationContext()).load(agriculture_temp.getImage()).into(image);
        data.setText(agriculture_temp.getTime());
        message.setText(agriculture_temp.getMessage());
    }

    Agriculture getData() throws JsonProcessingException {
        String agr_json=getIntent().getStringExtra("agr_json");
        Agriculture agriculture_t=JsonUtil.JsonToObj(agr_json,Agriculture.class);


        return agriculture_t;

    }



}